<template>
  <!-- 地址页面 -->
  <div class="address-view">
    <van-nav-bar left-arrow title="地址管理" @click-left="router.back()" />
    <van-address-list v-model="chosenAddressId" :list="userStore.Address" disabled-text="以下地址超出配送范围"
      default-tag-text="默认" @add="onAdd" @edit="onEdit" />
  </div>
</template>

<script setup lang="ts">
// 引入
import { AddressListAddress } from 'vant';
import { useUserStore } from '../store';
// 创建实例
const userStore = useUserStore();
const router = useRouter();
// 初始化地址数据
userStore.getAddress({ status: "getAddress", userId: localStorage.getItem("token") });

const chosenAddressId = ref('1');
// 点击新添地址
const onAdd = () => {
  userStore.AddressEdit= {
    name: "",
    tel: "",
    province: "",
    city: "",
    county: "",
    addressDetail: "",
    areaCode: "",
    isDefault: false
  }
  router.push("/addressEdit");
};
// 点击编辑地址
const onEdit = async(item: AddressListAddress) => {
  await userStore.getAddressEdit(String(item.id))
  router.push({path:"/addressEdit", query:{ id: item.id }});
};

</script>

<style scoped></style>
